import { log } from "console"

let age: number=12
console.log('----',age)
let arr: number[]=[1,2,3]
arr.forEach(val=>console.log('val:',val)
)
let arr1: Array<number>=[4,5]
 let arr3: (number|string)[]=['hi',333]
 // 类型别名：
 type CustomArray=(number|string)[]
 let arr4: CustomArray=[11,'dd']
 //函数类型
 function add(a: number,b: number): number{
return a+b
 }
 console.log('a+b',add(1,2))
 const add2=(a: number,b: number): number=>{
    return a+b
 }
 console.log('a+b',add(10,2))

 const add3: (a: number,b: number)=>number=(a,b)=>{
    return a+b
 }
 console.log('a+b',add3(10,2))

 function greet(name: string): void{
    console.log('hi',name)

 }
 greet('su')

 function mySlice(start?: number,end?: number):void{
    console.log('起始索引：', start, '结束索引：', end)
 }
 mySlice(1)

 //对象类型
 let person: {name: string;age: number;sayHi(): void}={
    name:'小张',
    age:12,
    sayHi(){}
 }
 function myAxios(config: {url: string;method?: string}){
console.log(config)
 }
 myAxios({
    url: ''
  })
 //接口
 interface IPerson{
    name: string
    age: number
    sayHi(): void
 }
 let person1: IPerson={ 
     name:'小明',
    age:22,
    sayHi(){}}
    type IPerson2={
        name: string
        age: number
        sayHi(): void
    }
    let person2: IPerson={ 
        name:'张三',
       age:32,
       sayHi(){}}
       interface Point2D{x: number,y: number}
       interface Point3D extends Point2D{z: number}
       let p: Point3D={ x: 1,
        y: 0,
        z: 0}

        //元组
        let position: [number,number]=[32.34,22.34]
        
//类型断言
//const aLink = document.getElementById('link') as HTMLAnchorElement
// const aLink = <HTMLAnchorElement>document.getElementById('link')
//aLink.href


//字面量类型
const str:'hello ts' ='hello ts'
function changeDirection(direction: 'up' | 'down' | 'left' | 'right'){

}

changeDirection('left')

//枚举
enum Direction{
    up,
    down,
    left,
    right
}
function changeDirection2(direction:Direction ){}
changeDirection2(Direction.down)

//any类型
let obj: any={a:1}
//typeof
let p2= {x:1,y: 2}
function formatPoint(point:{x: number,y: number} ){}
formatPoint(p2)
function formatPoint2(point:typeof p ){}

//高级类型
//类 构造函数
class Person{
    age: number
    gender: string
    constructor( age: number,gender: string){
this.age=age
this.gender=gender
    }
    sayHi(){
        console.log('hi')
        
    }
    protected move() {
        console.log('走两步')
      }
}
class Girl extends Person{
    name='陈都灵'
    eat(){
        console.log('吃饭')
    }
}
const p3=new Girl(14,'女')

console.log(p3.age,p3.gender,p3.name)
class Point {
    x = 1
    y = 2
  scale(n: number) {
      this.x *= n
      this.y *= n
    }
  }
  
  const p4 = new Point()
   p4.scale(10)
   console.log(p4.x, p4.y)

   interface Singable{
    name: string
    sing(): void
   }
   class Man implements Singable{
    name='周深'
sing(): void {
    console.log('大鱼');
    
}
   }
